package com.zhuo.common.domain.storage;

import java.util.Objects;

/**
 * 上传参数封装
 * 用于控制文件上传过程中的配置项，如文件夹、命名策略等
 */
public class UploadOptions {

    /**
     * 虚拟文件夹(key 前缀)，例如 "avatar/"
     */
    private String folder;

    /**
     * 文件名（不含 folder），如果为 null 则自动生成
     */
    private String fileName;

    /**
     * 文件key(如 avatar/asd.jpg ) 若指定key,就用这个key，如果为null，则按其它规则拼接生成
     */
    private String key;

    /**
     * 是否自动加日期前缀 yyyy/MM/dd
     */
    private Boolean datePrefix;

    /**
     * 是否在文件名中使用 UUID
     */
    private Boolean useUUID;

    /**
     * 文件大小
     */
    private Long fileSize;

    // todo 还可以拓展：存储类型、访问权限（public/private）、缓存过期时间等


    // ========================
    // 构造函数区域
    // ========================
    public UploadOptions() {
    }

    public UploadOptions(String folder) {
        this.folder = folder;
    }

    public UploadOptions(String folder, String fileName) {
        this.folder = folder;
        this.fileName = fileName;
    }

    public UploadOptions(String folder, String fileName, String key, boolean datePrefix, boolean useUUID) {
        this.folder = folder;
        this.fileName = fileName;
        this.key = key;
        this.datePrefix = datePrefix;
        this.useUUID = useUUID;
    }

    // ========================
    // Getter & Setter
    // ========================
    public String getFolder() {
        return folder;
    }

    public void setFolder(String folder) {
        this.folder = folder;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public Boolean getDatePrefix() {
        return datePrefix;
    }

    public void setDatePrefix(Boolean datePrefix) {
        this.datePrefix = datePrefix;
    }

    public Boolean getUseUUID() {
        return useUUID;
    }

    public void setUseUUID(Boolean useUUID) {
        this.useUUID = useUUID;
    }

    public Long getFileSize() {
        return fileSize;
    }

    public void setFileSize(Long fileSize) {
        this.fileSize = fileSize;
    }

    // ========================
    // equals / hashCode / toString
    // ========================
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof UploadOptions)) return false;
        UploadOptions that = (UploadOptions) o;
        return Objects.equals(folder, that.folder) &&
                Objects.equals(fileName, that.fileName) &&
                Objects.equals(key, that.key) &&
                Objects.equals(datePrefix, that.datePrefix) &&
                Objects.equals(useUUID, that.useUUID) &&
                Objects.equals(fileSize, that.fileSize);
    }

    @Override
    public int hashCode() {
        return Objects.hash(folder, fileName, key, datePrefix, useUUID, fileSize);
    }

    @Override
    public String toString() {
        return "UploadOptions{" +
                "folder='" + folder + '\'' +
                ", fileName='" + fileName + '\'' +
                ", key='" + key + '\'' +
                ", datePrefix=" + datePrefix +
                ", useUUID=" + useUUID +
                ", fileSize=" + fileSize +
                '}';
    }
}
